﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Data;

namespace GGHserver
{
    /// <summary>
    /// A megvalósításra váró metodokat interfészként fel kell venni.
    /// Ha valami módosításre került, azt a GGH projectben a servicereferenc
    ///     GghService-en updatelni kell, úgy, hogy 
    ///     build kell a gghserver projektre, majd ha az végzett
    ///     a gghserver release/bin  vagy debug/bin mappában lévő server alkalmazást (gghserver.exe)
    ///     el kell indítani, majd ha fút jobbclick update....
    ///     így elérhetővé válnak a megvalósított metódusok.
    ///     
    /// 
    /// 
    /// -------------
    /// ebbe az interfésze veszünk fel minden, a működéshez szükséges metódust.
    /// ha írtál az interfészbe, és impelmentálni akarod, a metúdus fejlécet a studio
    /// legenerálja ha ráálsz a class Service:IService részre és <ctrl>+<.> majd implement...
    /// </summary>
    [ServiceContract]
    public interface IService
    {
        #region teszthez
        [OperationContract]
        string ReciveInfo();
        [OperationContract]
        string SendAndReciveInfo( string _input );
        #endregion teszthez
        #region Usercontracts
        [OperationContract]
        string GetUseRolerbyNameAndPassword(string _username, string _password);
        [OperationContract]
        int CheckUserName(string _username);
        [OperationContract]
        void InsertUser(string _username, string _password, string _role);
        [OperationContract]
        void ModifyUser(string _username, string _password, string _role);
        [OperationContract]
        DataSet GetUsersData();
        #endregion Usercontracts
        #region StaticContracts

        [OperationContract]
        DataSet GetStaticByGroup(string _group);
        [OperationContract]
        DataSet GetStaticByName(string _name);
        [OperationContract]
        DataSet GetStaticByParent(string _parent);
        [OperationContract]
        DataSet GetStaticByID(int _id);
        [OperationContract]
        void InsertStatic(string _name, string _group, string _parent);
        [OperationContract]
        void ModifyStatic(int _id, string _name, string _group, string _parent);

        #endregion StaticContracts
        #region GuestContract

        [OperationContract]
        DataSet GetGuestByID(int _id);
        [OperationContract]
        void InsertGuest(string _name, string _email, string _address);
        [OperationContract]
        DataSet GetAllGuest();
        [OperationContract]
        void ModifyGuest(string _name, string _email, string _address, int _id);
        #endregion GuestContract
        #region roomContracts
        
        [OperationContract]
        DataSet GetAllRoomByHotelId(int _hotelid);
        [OperationContract]
        DataSet GetRoomById(int _roomid);
        [OperationContract]
        void InsertRoom(string _name, int _hotelid, int _capacity, string _description);
        [OperationContract]
        void ModifyRoom(string _name, int _hotelid, int _capacity, string _description, int _roomid);
        #endregion roomContracts
        #region reservationContracts
        //foglalás rögzítése
        [OperationContract]
        void InsertReservation(int _roomid, string _type, DateTime _start, DateTime _end, string _status);
        //foglalás módosításs
        [OperationContract]
        void ModifyResevation(int _roomid, string _type, DateTime _start, DateTime _end, string _status, int _id);

        #endregion reservationContracts
        #region billContracts

        [OperationContract]
        void CreateBill(int _guestid, int _price, DateTime _created, int _reservationid);
        //TODO: mi legyen a listában, ez lenne a statisztika alapja.
        [OperationContract]
        DataSet GetBillByDateBetween(DateTime _start, DateTime _end);
        [OperationContract]
        DataSet GetAllBill();
        #endregion billContracts
        #region premiseContracts

        [OperationContract]
        DataSet GetPremisesByRoomId(int _roomid);
        [OperationContract]
        DataSet GetPremiseById(int _id);
        [OperationContract]
        void InsertPremise(string _type, int _roomid, int _windows, int _balcony, int _climate);
        [OperationContract]
        void ModifyPremise(string _type, int _roomid, int _windows, int _balcony, int _climate, int _id);
        #endregion premiseContracts
        #region elementContracts

        [OperationContract]
        DataSet GetElementByID(int _id);
        [OperationContract]
        void InsertElement(int _premiseid, string _type, int _price, string _status, string _subtype, string _description);
        [OperationContract]
        void ModifyElement(int _premisesid, string _type, int _price, string _status, string _subtype, string _description, int _id);
        [OperationContract]
        DataSet GetElementByPremiseId(int _id);

        #endregion elementContracts
        #region searchContracts
        [OperationContract]
        DataSet GetFreeRoom();
        
        [OperationContract]
        DataSet GetUsedRoom();


        #endregion searchContracts

            
    }
    
 
    /// <summary>
    /// az interfész alapján implementálni kell a funkciókat.
    /// </summary>
    [ServiceBehavior]
    class Service:IService
    {
        #region teszthez
        public string ReciveInfo()
        {
            return "returnresult";
        }
        public string SendAndReciveInfo(string input)
        {
            return input + " ez jött ide";
        }
        #endregion teszthez

        #region user methods
        /// <summary>
        /// Lekéri a User Jogosultásgot felhasználónév és jelszó alapján
        /// </summary>
        /// <param name="Username"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        public string GetUseRolerbyNameAndPassword(string _username, string _password)
        {
            dbDataSetTableAdapters.UserTableAdapter ut = new dbDataSetTableAdapters.UserTableAdapter();
            dbDataSet.UserDataTable dt = new dbDataSet.UserDataTable();
            int a = ut.GetUserByNameAndPassword(dt , _username, _password);
            if (dt.Rows.Count == 1)
            { return dt.Rows[0]["Role"].ToString(); }
            else
            { return string.Empty; }
        }


        public int CheckUserName(string _username)
        {
            dbDataSetTableAdapters.UserTableAdapter ut = new dbDataSetTableAdapters.UserTableAdapter();
            int a = int.Parse(ut.CheckUserName(_username).ToString());
            return a;
        }

        public void InsertUser(string _username, string _password, string _role)
        {
            dbDataSetTableAdapters.UserTableAdapter ut = new dbDataSetTableAdapters.UserTableAdapter();
            dbDataSet.UserDataTable dt = new dbDataSet.UserDataTable();
            int a = ut.InserUser(_username, _password,_role);
           
        }

        public void ModifyUser(string _username, string _password, string _role)
        {
            dbDataSetTableAdapters.UserTableAdapter ut = new dbDataSetTableAdapters.UserTableAdapter();
            int a = ut.ModifyUser(_username, _password, _role); 
        }

        public DataSet GetUsersData()
        {
            dbDataSetTableAdapters.UserTableAdapter ut = new dbDataSetTableAdapters.UserTableAdapter();
            dbDataSet.UserDataTable dt = new dbDataSet.UserDataTable();
            dt = ut.GetData();
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            return ds;
            
        }
        #endregion Usermethods

        #region Staticmethods


        public DataSet GetStaticByGroup(string _group)
        {
            dbDataSetTableAdapters.StaticTableAdapter st = new dbDataSetTableAdapters.StaticTableAdapter();
            dbDataSet.StaticDataTable dt = new dbDataSet.StaticDataTable();
            dt = st.GetStaticByGroup(_group);

            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            return ds;
 
        }

        public DataSet GetStaticByName(string _name)
        {
            dbDataSetTableAdapters.StaticTableAdapter st = new dbDataSetTableAdapters.StaticTableAdapter();
            dbDataSet.StaticDataTable dt = new dbDataSet.StaticDataTable();
            dt = st.GetStaticByName(_name);
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            return ds;
 
        }

        public DataSet GetStaticByParent(string _parent)
        {
            dbDataSetTableAdapters.StaticTableAdapter st = new dbDataSetTableAdapters.StaticTableAdapter();
            dbDataSet.StaticDataTable dt = new dbDataSet.StaticDataTable();
            dt = st.GetStaticByParent(_parent);
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            return ds;
 
        }

        public DataSet GetStaticByID(int _id)
        {
            dbDataSetTableAdapters.StaticTableAdapter st = new dbDataSetTableAdapters.StaticTableAdapter();
            dbDataSet.StaticDataTable dt = new dbDataSet.StaticDataTable();
            dt = st.GetStaticByID(_id);
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            return ds;
 
        }

        public void InsertStatic(string _name, string _group, string _parent)
        {
            dbDataSetTableAdapters.StaticTableAdapter st = new dbDataSetTableAdapters.StaticTableAdapter();
            st.InsertStatic(_name, _group, _parent);
            
        }

        public void ModifyStatic(int _id, string _name, string _group, string _parent)
        {
            dbDataSetTableAdapters.StaticTableAdapter st = new dbDataSetTableAdapters.StaticTableAdapter();
            st.UpdateStatic(_name, _group, _parent, _id);
            
        }
        #endregion Staticmethods

        #region Guest methods
        
        public DataSet GetGuestByID(int _id)
        {
            dbDataSetTableAdapters.GuestTableAdapter gt = new dbDataSetTableAdapters.GuestTableAdapter();
            dbDataSet.GuestDataTable dt = new dbDataSet.GuestDataTable();
            
            dt = gt.GetGuestByID(_id);
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            return ds;
 
        }

        public void InsertGuest(string _name, string _email, string _address)
        {
            dbDataSetTableAdapters.GuestTableAdapter gt = new dbDataSetTableAdapters.GuestTableAdapter();
            gt.InsertGuest(_name, _email, _address);
        }
        
        public DataSet GetAllGuest()
        {
            dbDataSetTableAdapters.GuestTableAdapter gt = new dbDataSetTableAdapters.GuestTableAdapter();
            dbDataSet.GuestDataTable dt = new dbDataSet.GuestDataTable();
            dt = gt.GetData();
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            return ds;
        }

        public void ModifyGuest(string _name, string _email, string _address, int _id)
        {
            dbDataSetTableAdapters.GuestTableAdapter gt = new dbDataSetTableAdapters.GuestTableAdapter();
            gt.ModifyGuest(_name, _email, _address, _id);
        }

        #endregion Guest methods

        #region RoomMethods

        public DataSet GetAllRoomByHotelId(int _hotelid)
        {
            dbDataSetTableAdapters.roomTableAdapter gt = new dbDataSetTableAdapters.roomTableAdapter();
            dbDataSet.roomDataTable dt = new dbDataSet.roomDataTable();
            dt = gt.GetDataByHotelID(_hotelid);
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            return ds;
 
        }

        public DataSet GetRoomById(int _roomid)
        {
            dbDataSetTableAdapters.roomTableAdapter gt = new dbDataSetTableAdapters.roomTableAdapter();
            dbDataSet.roomDataTable dt = new dbDataSet.roomDataTable();
            dt = gt.GetRoomByID(_roomid);
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            return ds;
 
        }

        public void InsertRoom(string _name, int _hotelid, int _capacity, string _description)
        {
            dbDataSetTableAdapters.roomTableAdapter gt = new dbDataSetTableAdapters.roomTableAdapter();
            gt.InsertRoom(_name, _hotelid, _capacity, _description);
            
        }

        public void ModifyRoom(string _name, int _hotelid, int _capacity, string _description, int _roomid)
        {
            dbDataSetTableAdapters.roomTableAdapter gt = new dbDataSetTableAdapters.roomTableAdapter();
            gt.ModifyRoom(_name, _hotelid, _capacity, _description, _roomid);
        }
        #endregion RoomMethods

        #region ReservationMethods
        public void InsertReservation(int _roomid, string _type, DateTime _start, DateTime _end, string _status)
        {
            dbDataSetTableAdapters.reservationTableAdapter gt = new dbDataSetTableAdapters.reservationTableAdapter();
            gt.InsertReservation(_roomid, _type, _start, _end, _status);
        }

        public void ModifyResevation(int _roomid, string _type, DateTime _start, DateTime _end, string _status, int _id)
        {
            dbDataSetTableAdapters.reservationTableAdapter gt = new dbDataSetTableAdapters.reservationTableAdapter();
            gt.UpdateReservation(_roomid, _type, _start, _end, _status, _id);
        }
        
        #endregion

        #region Billmethods

        public void CreateBill(int _guestid, int _price, DateTime _created, int _reservationid)
        {
            dbDataSetTableAdapters.billTableAdapter gt = new dbDataSetTableAdapters.billTableAdapter();
            gt.CreateBill(_guestid, _price.ToString(), _created, _reservationid);
        }

        public DataSet GetBillByDateBetween(DateTime _start, DateTime _end)
        {
            dbDataSetTableAdapters.billTableAdapter gt = new dbDataSetTableAdapters.billTableAdapter();
            dbDataSet.billDataTable dt = new dbDataSet.billDataTable();
            dt = gt.GetBillByDateBetween(_start, _end);
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            return ds;
 
        }

        public DataSet GetAllBill()
        {
            dbDataSetTableAdapters.billTableAdapter gt = new dbDataSetTableAdapters.billTableAdapter();
            var dt = gt.GetData();
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            return ds;
 
        }
        #endregion

        #region premisemethods
        public DataSet GetPremisesByRoomId(int _roomid)
        {
            dbDataSetTableAdapters.premiseTableAdapter gt = new dbDataSetTableAdapters.premiseTableAdapter();
            var dt = gt.GetPremiseByRoomID(_roomid);
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            return ds;
 
        }

        public void InsertPremise(string _type, int _roomid, int _windows, int _balcony, int _climate)
        {
            dbDataSetTableAdapters.premiseTableAdapter gt = new dbDataSetTableAdapters.premiseTableAdapter();
            gt.InsertPremise(_type, _roomid, _windows, _balcony, _climate);
        }

        public void ModifyPremise(string _type, int _roomid, int _windows, int _balcony, int _climate, int _id)
        {
            dbDataSetTableAdapters.premiseTableAdapter gt = new dbDataSetTableAdapters.premiseTableAdapter();
            gt.ModifyPremise(_type, _roomid, _windows, _balcony, _climate,_id);
        }


        public DataSet GetPremiseById(int _id)
        {
            dbDataSetTableAdapters.premiseTableAdapter gt = new dbDataSetTableAdapters.premiseTableAdapter();
            var dt = gt.GetPremiseById(_id);
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            return ds;
        }

        #endregion

        #region elementMethods
        public DataSet GetElementByID(int _id)
        {
            dbDataSetTableAdapters.elementTableAdapter gt = new dbDataSetTableAdapters.elementTableAdapter();
            var dt = gt.GetElementByID(_id);
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            return ds;
 
        }

        public void InsertElement(int _premiseid, string _type, int _price, string _status, string _subtype, string _description)
        {
            dbDataSetTableAdapters.elementTableAdapter gt = new dbDataSetTableAdapters.elementTableAdapter();
            gt.InsertElement(_premiseid, _type, _price, _status, _subtype, _description);
        }

        public void ModifyElement(int _premisesid, string _type, int _price, string _status, string _subtype, string _description, int _id)
        {
            dbDataSetTableAdapters.elementTableAdapter gt = new dbDataSetTableAdapters.elementTableAdapter();
            gt.ModifyElement(_premisesid, _type, _price, _status, _subtype, _description,_id);
        }
        /// <summary>
        /// adatbázis oszlopnév hiba
        /// </summary>
        /// <param name="_id"></param>
        /// <returns></returns>
        public DataSet GetElementByPremiseId(int _id)
        {
            dbDataSetTableAdapters.elementTableAdapter gt = new dbDataSetTableAdapters.elementTableAdapter();
            var dt = gt.GetElementByRoomId(_id);
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            return ds;
        }
        #endregion
        #region searchmethods

        public DataSet GetFreeRoom()
        {
            dbDataSetTableAdapters.roomTableAdapter gt = new dbDataSetTableAdapters.roomTableAdapter();
            var dt =  gt.GetFreeRooms();
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            return ds;
        }

        public DataSet  GetUsedRoom()
        {
            dbDataSetTableAdapters.roomTableAdapter gt = new dbDataSetTableAdapters.roomTableAdapter();
            var dt =  gt.GetUsedRoom();
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            return ds;
        }
        #endregion
    }
}


